<%@ include file="/common/taglibs.jsp"%>

<head>
    <title><fmt:message key="noticiaDetail.title"/></title>
    <meta name="heading" content="<fmt:message key='noticiaDetail.heading'/>"/>
</head>

<script type="text/javascript" src="<c:url value='/FCKeditor/fckeditor.js'/>"></script>


<s:form id="noticiaForm" action="saveNoticia" method="post" validate="true" onsubmit="return guardarHTML();">
<s:hidden name="noticia.id" value="%{noticia.id}"/>

    <s:textfield key="noticia.titulo" required="true" cssClass="text medium"/>
    <s:textfield key="noticia.autor" required="true" cssClass="text medium"/>
	<s:select key="seccionSeleccionada" label="Seccion" required="true" list="secciones" />
<!--    <s:textfield key="keywords" cssClass="text medium"/> -->
    <s:hidden key="noticia.resumen" required="true" cssClass="text medium"/>
    <s:hidden key="noticia.contenido" required="true" cssClass="text medium"/>
<div class="wwlbl"><label class="desc">Resumen</label></div> 
    
    <span id="editorResumen">
	    <script type="text/javascript">
		    var oFCKeditor = new FCKeditor( "resumen" ) ;
		    oFCKeditor.BasePath = "<c:url value='/FCKeditor/'/>" ;
		    oFCKeditor.Config["CustomConfigurationsPath"] = "<c:url value='/FCKeditor/fckadntoolbars.js?'/>" + ( new Date() * 1 );
		    oFCKeditor.Height = 250;
		    oFCKeditor.Width = 640;
			oFCKeditor.ToolbarSet = "Adn";
			oFCKeditor.Create();
		</script>
    </span>    
<div class="wwlbl"><label class="desc">Contenido</label></div> 
    
    <span id="editorContenido">
	    <script type="text/javascript">
		    var oFCKeditor = new FCKeditor( "contenido" ) ;
		    oFCKeditor.BasePath = "<c:url value='/FCKeditor/'/>" ;
		    oFCKeditor.Config["CustomConfigurationsPath"] = "<c:url value='/FCKeditor/fckadntoolbars.js?'/>" + ( new Date() * 1 );
		    oFCKeditor.Height = 400;
		    oFCKeditor.Width = 640;
			oFCKeditor.ToolbarSet = "Adn";
			oFCKeditor.Create();
		</script>
    </span>
    <s:hidden key="noticia.fechaCreacion" />
    <s:hidden key="noticia.fechaBaja" />


    <li class="buttonBar bottom">         
        <s:submit cssClass="button" method="save" key="button.save" theme="simple"/>
        <c:if test="${not empty noticia.id}"> 
	        <c:if test="${noticia.fechaBaja == null}"> 
	            <s:submit cssClass="button" method="delete" key="button.delete" onclick="return confirmDelete('noticia')" theme="simple"/>
	        </c:if>
	        <c:if test="${noticia.fechaBaja != null}"> 
	            <s:submit cssClass="button" method="delete" key="button.restaurar" onclick="return confirmDelete('noticia')" theme="simple"/>
	        </c:if>
        </c:if>
        <s:submit cssClass="button" method="cancel" key="button.preview" onclick="showNewsPreview();return false;" theme="simple"/>
        <s:submit cssClass="button" method="cancel" key="button.cancel" theme="simple"/>
    </li>
</s:form>

<script type="text/javascript">
    Form.focusFirstElement($("noticiaForm"));

</script>


<form id="form2" name="form2" action="verNoticia.html" target="_blank" method="POST">
	<input type="hidden" name="titulo" id="preview_titulo">
	<input type="hidden" name="idSeccion" id="preview_idSeccion">
	<input type="hidden" name="autor" id="preview_autor">
	<input type="hidden" name="contenido" id="preview_contenido">
	<input type="hidden" name="resumen" id="preview_resumen">
</form>

<script type="text/javascript">
    <!--
/*    function ReplaceAllTextareas() {
            // replace all of the textareas
            var allTextAreas = document.getElementsByTagName("textarea");
            for (var i=0; i < allTextAreas.length; i++) {
                var oFCKeditor = new FCKeditor( allTextAreas[i].name ) ;
                oFCKeditor.BasePath = "<c:url value='/FCKeditor/'/>" ;
                oFCKeditor.Config["CustomConfigurationsPath"] = "<c:url value='/FCKeditor/fckadntoolbars.js?'/>" + ( new Date() * 1 );
                oFCKeditor.Height = 350;
				oFCKeditor.ToolbarSet = "Adn";
                oFCKeditor.ReplaceTextarea() ;
            }
    }
    ReplaceAllTextareas();*/
    
    function guardarHTML() {
		var oEditor = FCKeditorAPI.GetInstance("contenido");
    	document.getElementById("noticiaForm_noticia_contenido").value = oEditor.GetHTML().replace(/<br type="_moz" \/>/g,""); 
		oEditor = FCKeditorAPI.GetInstance("resumen");
    	document.getElementById("noticiaForm_noticia_resumen").value = oEditor.GetHTML().replace(/<br type="_moz" \/>/g,""); 
    }
	function FCKeditor_OnComplete( editorInstance )	{
		if ((editorInstance.Name != "contenido") && (editorInstance.Name != "resumen"))  return;
		if (editorInstance.Name == "contenido"){
			editorInstance.SetHTML(
				document.getElementById("noticiaForm_noticia_contenido").value.replace(/<br type="_moz" \/>/g,"")
			);
		}
		if (editorInstance.Name == "resumen"){
			editorInstance.SetHTML(
				document.getElementById("noticiaForm_noticia_resumen").value.replace(/<br type="_moz" \/>/g,"")
			);
		}
	}    
    
    
	function showNewsPreview() {
		document.getElementById("preview_titulo").value = document.getElementById("noticiaForm_noticia_titulo").value;
		document.getElementById("preview_autor").value = document.getElementById("noticiaForm_noticia_autor").value;
		document.getElementById("preview_idSeccion").value = document.getElementById("noticiaForm_seccionSeleccionada").value;
		var oEditor2 = FCKeditorAPI.GetInstance('contenido');
		document.getElementById("preview_contenido").value = oEditor2.GetHTML().replace(/<br type="_moz" \/>/g,"");
		var oEditor = FCKeditorAPI.GetInstance('resumen');
		document.getElementById("preview_resumen").value = oEditor.GetHTML().replace(/<br type="_moz" \/>/g,"");
		document.form2.submit();
	}        
    // -->
</script>  
